<template>
  <view class="container">
    <view></view>
    <view class="pub_ad_banner">
      <!-- #ifdef MP-TOUTIAO -->
      <ad
        :unit-id="adBannerIdDouyin"
        :ad-intervals="30"
        :fixed="false"
        type="banner"
        scale="100"
      />
      <!-- #endif -->
      <!-- #ifdef MP-KUAISHOU -->
      <ad :type="100011054" :unit-id="adBannerIdKuaishou"></ad>
      <!-- #endif -->
    </view>
  </view>
</template>

<script>
import {
  showAdConfirmModal,
  adVideoCreate,
  adVideoShow,
  adBannerIdDouyin,
  adBannerIdKuaishou,
} from "@/common/ad";
export default {
  data() {
    return {
      adBannerIdDouyin: adBannerIdDouyin,
      adBannerIdKuaishou: adBannerIdKuaishou,
      showResult: false,
      isUnlock: false,
      formData: {
        calcTypeIndex: 0,
        principal: "",
        totalValue: "",
        rate: "",
        rateTypeIndex: 0,
        years: "",
        periodTypeIndex: 0,
        compoundingIndex: 0,
      },
      result: {
        total: "",
        detail: {},
      },
      canSubmit: false,
    };
  },
  onLoad() {
    adVideoCreate();
  },
  watch: {
    formData: {
      handler: function () {
        this.canSubmit = this.checkFormValid();
      },
      deep: true,
    },
  },
  methods: {
    calculate() {
      this.showResult = true;
      this.isUnlock = true;
    },
    getResult() {
      this.calculate();
    },
    submit() {
      if (this.formData.calcTypeIndex === 0 && this.formData.principal == "") {
        this.global.toast("请输入本金");
        return;
      }
      if (this.formData.calcTypeIndex === 1 && this.formData.totalValue == "") {
        this.global.toast("请输入本息合计");
        return;
      }
      if (this.formData.rate == "") {
        this.global.toast("请输入利率");
        return;
      }
      if (this.formData.years == "") {
        this.global.toast("请输入期数");
        return;
      }
      if (!this.isUnlock) {
        showAdConfirmModal(() => {
          try {
            adVideoShow(() => {
              this.getResult();
            });
          } catch (error) {
            this.getResult();
          }
        });
      } else {
        this.getResult();
      }
    },
  },
};
</script>

<style scoped lang="scss">

</style>